import RightLevels from './datas/user/right_levels.json'
import UserMedals from './datas/user/user_medals.json'
import MainPageCategoryRights from './datas/user/main_page_category_rights.json'
import UserInfo from './datas/user/userinfo.json'

const USER_INFO_KEY = 'mxbc_user_info'
const userInfo = uni.getStorageSync(USER_INFO_KEY)

export default {
    namespaced: true,
    state: {
        userInfo: userInfo || null,
        rightLevels: RightLevels,
        userMedals: UserMedals,
        mainPageCategoryRights: MainPageCategoryRights,
    },
    getters: {
        lightCount: state => state.userMedals.filter(medal => medal.lightFlag).length,
        medalPreview: state => state.userMedals.slice(0, 8)
    },
    mutations: {
        SET_USER_INFO (state, userInfo) {
            state.userInfo = userInfo
            uni.setStorageSync(USER_INFO_KEY, userInfo)
        }
    },
    actions: {
        login ({ commit }) {
            commit('SET_USER_INFO', UserInfo)
        }
    }
}